Add gdk_texture_save_to_png_bytes
authorMatthias Clasen <mclasen@redhat.com>
Mon, 13 Sep 2021 18:29:31 +0000 (14:29 -0400)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 22:25:22 +0000 (00:25 +0200)
Just expose what we already have available
internally, so e.g. tests can use it without
static linking.

gdk/gdktexture.c
gdk/gdktexture.h

index 973a6f923ab2f3bd4b4123a5b46b6c6bc7a3cca4..85b5be28bb68be4a67d16740ba55bba04257cd00 100644 (file)
@@ -690,7 +690,8 @@ gdk_texture_get_render_data (GdkTexture  *self,
  * This is a utility function intended for debugging and testing.
  * If you want more control over formats, proper error handling or
  * want to store to a `GFile` or other location, you might want to
- * look into using the gdk-pixbuf library.
+ * use [method@Gdk.Texture.save_to_png_bytes] or look into the
+ * gdk-pixbuf library.
  *
  * Returns: %TRUE if saving succeeded, %FALSE on failure.
  */
@@ -713,3 +714,29 @@ gdk_texture_save_to_png (GdkTexture *texture,
 
   return result;
 }
+
+/**
+ * gdk_texture_save_to_png_bytes:
+ * @texture: a `GdkTexture`
+ *
+ * Store the given @texture in memory as a PNG file.
+ * Use [ctor@Gdk.Texture.new_from_bytes] to read it back.
+ *
+ * If you want to serialize a texture, this is a convenient and
+ * portable way to do that.
+ *
+ * If you need more control over the generated image, such as
+ * attaching metadata, you should look into an image handling
+ * library such as the gdk-pixbuf library.
+ *
+ * Returns: a newly allocated `GBytes` containing PNG data
+ *
+ * Since: 4.6
+ */
+GBytes *
+gdk_texture_save_to_png_bytes (GdkTexture *texture)
+{
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
+
+  return gdk_save_png (texture);
+}
index 927eb11bdfbd89c4f8fbe4fe8258d69e10793953..7e7de473d8b465fa3bdf7dd93ea1d924f30aff82 100644 (file)
@@ -91,6 +91,8 @@ void                    gdk_texture_download_float             (GdkTexture
 GDK_AVAILABLE_IN_ALL
 gboolean                gdk_texture_save_to_png                (GdkTexture      *texture,
                                                                 const char      *filename);
+GDK_AVAILABLE_IN_4_6
+GBytes *                gdk_texture_save_to_png_bytes          (GdkTexture      *texture);
 
 G_END_DECLS